﻿using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zad4
{
    public delegate void ChangedEventHandler();

    class serwer
    {
        public string text1, text2, text3;
        bool direction = false; //true northbound, false southbound
        public event ChangedEventHandler Changed;
        Queue<Thread> south;
        Queue<Thread> north;
        
        public void daem()
        {
            while (true)
            {
                if (direction)
                {
                    if (northcount <= 0) direction = false;
                }
                else if (southcount <= 0) direction = true;
                if (direction)
                {
                    northcount--;
                    if (northcount < 0) northcount = 0;
                }
                else
                {
                    southcount--;
                    if (southcount < 0) southcount = 0;
                }

                if (direction) text1 = "Direction: north";
                else text1 = "Direction: south";
                text2 = "Northbound: " + northcount.ToString();
                text3 = "Southbound: " + southcount.ToString();
                if (Changed != null) Changed();
                Thread.Sleep(1000);
            }
        }

        public bool wejscieN()
        {
            return true;
        }

        public bool wejscieS()
        {
            return true;
        }
    }
}
